package com.meitianhui.convenitenbuy.module.home.adapter;

import android.content.Context;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.meitianhui.convenitenbuy.R;
import com.meitianhui.convenitenbuy.module.home.model.bean.FreePaper;
import com.meitianhui.convenitenbuy.util.LogUtils;
import com.meitianhui.convenitenbuy.util.StringUtils;

import java.util.List;

/**
 * 免单券适配器
 */

public class FreePaperAdapter extends BaseQuickAdapter<FreePaper.ListBean, BaseViewHolder> {
    private Context mContext;
    private int mCheck;
    private String mDiscountPrice;
    public FreePaperAdapter(Context context, @Nullable List<FreePaper.ListBean> data,String discountPrice) {
        super(R.layout.item_free_paper, data);
        mContext = context;
        mDiscountPrice = discountPrice;
    }

    public void setCheck(int check) {
        this.mCheck = check;
    }

    @Override
    protected void convert(BaseViewHolder helper, FreePaper.ListBean item) {
        TextView tvTitle = helper.getView(R.id.tv_title);
        TextView tvSelect = helper.getView(R.id.tv_select);
        if (StringUtils.moneyComp(item.getLimited_price(),mDiscountPrice)) {
            helper.setBackgroundRes(R.id.ll_left, R.mipmap.icon_free_paper_press);
            helper.setBackgroundRes(R.id.ll_right, R.drawable.icon_free_paper_bg_press);
            tvSelect.setVisibility(View.VISIBLE);
            tvTitle.setTextColor(mContext.getResources().getColor(R.color.white));
            helper.setTextColor(R.id.tv_number, mContext.getResources().getColor(R.color.white));
            helper.setTextColor(R.id.tv_limit_price, mContext.getResources().getColor(R.color.white));
            helper.setTextColor(R.id.tv_limit_time, mContext.getResources().getColor(R.color.white));
        } else {
            helper.setBackgroundRes(R.id.ll_left, R.mipmap.icon_free_paper_normal);
            helper.setBackgroundRes(R.id.ll_right, R.mipmap.icon_free_paper_bg_normal);
            tvSelect.setVisibility(View.GONE);
            tvTitle.setTextColor(mContext.getResources().getColor(R.color.textColorWeak));
            helper.setTextColor(R.id.tv_number, mContext.getResources().getColor(R.color.textColorWeak));
            helper.setTextColor(R.id.tv_limit_price, mContext.getResources().getColor(R.color.textColorWeak));
            helper.setTextColor(R.id.tv_limit_time, mContext.getResources().getColor(R.color.textColorWeak));
        }
        String title = item.getRemark();
        if (TextUtils.isEmpty(title)) {
            tvTitle.setText("系统赠送");
        } else {
            tvTitle.setText(item.getRemark());
        }
        helper.setText(R.id.tv_number, item.getPrivate_key());
        helper.setText(R.id.tv_limit_price, "限制金额  " + item.getLimited_price());
        helper.setText(R.id.tv_limit_time, "截止日期  " + item.getExpired_date());
        LogUtils.d("position",getParentPosition(item)+"");
        if (mCheck == helper.getLayoutPosition()) {
            tvSelect.setBackgroundResource(R.mipmap.rb_free_paper_normal);
        } else {
            tvSelect.setBackgroundResource(R.mipmap.rb_free_paper_select);

        }
    }

}
